package service

import (
	"github.com/gin-gonic/gin"
	"github.com/astaxie/beego/orm"
	"talentsystem/model"
)

func Gettransfer (c*gin.Context){
	var msg model.Transfer
	_,err:=orm.NewOrm().QueryTable("transfer").All(&msg)
	if err!=nil{
		c.JSON(500,gin.H{
			"status":500,
			"msg":"系统错误请刷新",
		})
		return
	}
	c.JSON(200,gin.H{
		"status":200,
		"data":msg,
	})
	return
}
func UpdateTranfer(c*gin.Context){
	var param model.Transfer
	if err:=c.Bind(&param);err!=nil{
		c.JSON(403,gin.H{
			"status":403,
			"msg":"参数格式不正确",
		})
		return
	}
	num,err:=orm.NewOrm().QueryTable("transfer").Filter("id",param.Id).Update(orm.Params{
		"Amount":param.Amount,
		"Way":param.Way,
		"AccountName":param.AccountName,
		"QrcodeUrl":param.QrcodeUrl,
	})
	if err!=nil{
		c.JSON(500,gin.H{
			"status":500,
			"msg":"系统错误请刷新",
		})
		return
	}
	if num ==0 {
		c.JSON(403,gin.H{
			"status":403,
			"msg":"数值未改变，修改失败",
		})
		return
	}
	c.JSON(200,gin.H{
		"status":200,
		"msg":1,
	})
	return
}
func InsertTranfer (c*gin.Context){
	transfer:=new(model.Transfer)
	transfer.Amount="365"
	transfer.Way=0
	transfer.AccountName="zhuojuxian@163.com"
	transfer.QrcodeUrl="img/20171224162314.png"
	_,err:=orm.NewOrm().Insert(transfer)
	if err!=nil {
		c.JSON(500,gin.H{
			"status":500,
			"msg":"系统错误请刷新",
		})
		return
	}
	c.JSON(200,gin.H{
		"status":200,
		"msg":"初始化成功",
	})
	return
}